package com.fw.payment.bao;

import static org.springframework.beans.factory.config.BeanDefinition.SCOPE_PROTOTYPE;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.fw.payment.service.ServiceExecutor;
import com.fw.payment.service.ServiceOrder;
import com.fw.service.bean.EntryBean;
import com.fw.service.bean.SearchCriteriaBean;
import com.fw.service.bean.SearchResultBean;
import com.fw.service.bouser.BOUserService;
import com.fw.service.bouser.bean.BOUserBean;
import com.fw.service.bouser.bean.SearchBOUserBean;

@Component
@Scope(SCOPE_PROTOTYPE)
public class BOUserBAO extends AbstractBAO implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Autowired
    private BOUserService boUserService;

    @SuppressWarnings("unchecked")
    public Map<String, Serializable> createBOUser(BOUserBean boUserBean) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.boUserService);
	    serviceOrder.setMethodName("createBOUser");
	    serviceOrder.setParameterTypes(new Class[] { BOUserBean.class });
	    serviceOrder.setParameterValues(new Object[] { boUserBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		List<EntryBean<String, Serializable>> entryBeans = (List<EntryBean<String, Serializable>>) serviceOrder.getReturnValue();
		if (entryBeans != null) {
		    Map<String, Serializable> map = new HashMap<String, Serializable>();
		    for (EntryBean<String, Serializable> entryBean : entryBeans) {
			map.put(entryBean.getKey(), entryBean.getValue());
		    }
		    return map;
		}
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    public BOUserBean getBOUser(Long id) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.boUserService);
	    serviceOrder.setMethodName("getBOUser");
	    serviceOrder.setParameterTypes(new Class[] { Long.class });
	    serviceOrder.setParameterValues(new Object[] { id });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		BOUserBean result = (BOUserBean) serviceOrder.getReturnValue();
		return result;
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    @SuppressWarnings("unchecked")
    public Map<String, Serializable> updateBOUser(BOUserBean boUserBean) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.boUserService);
	    serviceOrder.setMethodName("updateBOUser");
	    serviceOrder.setParameterTypes(new Class[] { BOUserBean.class });
	    serviceOrder.setParameterValues(new Object[] { boUserBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		List<EntryBean<String, Serializable>> entryBeans = (List<EntryBean<String, Serializable>>) serviceOrder.getReturnValue();
		if (entryBeans != null) {
		    Map<String, Serializable> map = new HashMap<String, Serializable>();
		    for (EntryBean<String, Serializable> entryBean : entryBeans) {
			map.put(entryBean.getKey(), entryBean.getValue());
		    }
		    return map;
		}
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    @SuppressWarnings("unchecked")
    public Map<String, Serializable> deleteBOUser(BOUserBean boUserBean) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.boUserService);
	    serviceOrder.setMethodName("deleteBOUser");
	    serviceOrder.setParameterTypes(new Class[] { BOUserBean.class });
	    serviceOrder.setParameterValues(new Object[] { boUserBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		List<EntryBean<String, Serializable>> entryBeans = (List<EntryBean<String, Serializable>>) serviceOrder.getReturnValue();
		if (entryBeans != null) {
		    Map<String, Serializable> map = new HashMap<String, Serializable>();
		    for (EntryBean<String, Serializable> entryBean : entryBeans) {
			map.put(entryBean.getKey(), entryBean.getValue());
		    }
		    return map;
		}
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    public Boolean checkUniqueUsername(String username) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.boUserService);
	    serviceOrder.setMethodName("checkUniqueUsername");
	    serviceOrder.setParameterTypes(new Class[] { String.class });
	    serviceOrder.setParameterValues(new Object[] { username });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		Boolean result = (Boolean) serviceOrder.getReturnValue();
		return result;
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    @SuppressWarnings("unchecked")
    public List<BOUserBean> selectAllBOUser() throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.boUserService);
	    serviceOrder.setMethodName("selectAllBOUser");
	    serviceOrder.setParameterTypes(new Class[] {});
	    serviceOrder.setParameterValues(new Object[] {});

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		List<BOUserBean> result = (List<BOUserBean>) serviceOrder.getReturnValue();
		return result;
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    @SuppressWarnings("unchecked")
    public SearchResultBean<BOUserBean> selectBOUser(SearchCriteriaBean<SearchBOUserBean> searchCriteriaBean) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.boUserService);
	    serviceOrder.setMethodName("selectBOUser");
	    serviceOrder.setParameterTypes(new Class[] { SearchCriteriaBean.class });
	    serviceOrder.setParameterValues(new Object[] { searchCriteriaBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		SearchResultBean<BOUserBean> result = (SearchResultBean<BOUserBean>) serviceOrder.getReturnValue();
		return result;
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    @SuppressWarnings("unchecked")
    public Map<String, Serializable> resetPasswordBOUser(BOUserBean boUserBean) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.boUserService);
	    serviceOrder.setMethodName("resetPasswordBOUser");
	    serviceOrder.setParameterTypes(new Class[] { BOUserBean.class });
	    serviceOrder.setParameterValues(new Object[] { boUserBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		List<EntryBean<String, Serializable>> entryBeans = (List<EntryBean<String, Serializable>>) serviceOrder.getReturnValue();
		if (entryBeans != null) {
		    Map<String, Serializable> map = new HashMap<String, Serializable>();
		    for (EntryBean<String, Serializable> entryBean : entryBeans) {
			map.put(entryBean.getKey(), entryBean.getValue());
		    }
		    return map;
		}
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

    @SuppressWarnings("unchecked")
    public Map<String, Serializable> changePasswordBOUser(BOUserBean boUserBean) throws Exception {
	try {
	    ServiceOrder serviceOrder = new ServiceOrder();
	    serviceOrder.setServiceClass(this.boUserService);
	    serviceOrder.setMethodName("changePasswordBOUser");
	    serviceOrder.setParameterTypes(new Class[] { BOUserBean.class });
	    serviceOrder.setParameterValues(new Object[] { boUserBean });

	    ServiceExecutor serviceExecutor = new ServiceExecutor(serviceOrder, timeout);
	    serviceOrder = serviceExecutor.callService();
	    if (serviceOrder.getResultCode() != null && serviceOrder.getResultCode().equals(new Integer(0))) {
		List<EntryBean<String, Serializable>> entryBeans = (List<EntryBean<String, Serializable>>) serviceOrder.getReturnValue();
		if (entryBeans != null) {
		    Map<String, Serializable> map = new HashMap<String, Serializable>();
		    for (EntryBean<String, Serializable> entryBean : entryBeans) {
			map.put(entryBean.getKey(), entryBean.getValue());
		    }
		    return map;
		}
	    }
	} catch (Exception e) {
	    throw e;
	}
	return null;
    }

}
